<template>
	<div style="width: 500px;">
		
		<el-form ref="form" label-width="150px">
			<el-form-item label="是否自动开盘:">
				<el-radio-group v-model="config.is_auto_open">
				  <el-radio label="0">关闭</el-radio>
				  <el-radio label="1">开启</el-radio>
				</el-radio-group>
			</el-form-item>
			<div v-if="config.is_auto_open==1">
				<el-form-item label="开启时间:">
					<el-time-picker
						value-format="HH:mm:ss"
						size="small"
					    v-model="config.open_time"
					    placeholder="请选择开启时间">
					</el-time-picker>
				</el-form-item>
				<el-form-item label="关闭时间:">
					<el-time-picker
						value-format="HH:mm:ss"
						size="small"
					    v-model="config.colse_time"
					    placeholder="请选择关闭时间">
					</el-time-picker>
				</el-form-item>
			</div>
			
			<el-form-item label="是否开盘:">
				<el-radio-group v-model="config.status">
				  <el-radio label="0">关盘</el-radio>
				  <el-radio label="1">开盘</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="价格保留位数:">
				<el-radio-group  v-model="config.fixNum">
				  <el-radio label="10">一位</el-radio>
				  <el-radio label="100">两位</el-radio>
				</el-radio-group>
			</el-form-item>
			<!-- <el-form-item label="最大定价数量:">
				<el-input v-model="config.max_weight" type="number" size="small"></el-input>
			</el-form-item> -->
			<el-form-item label="最小定价数量:">
				<el-input v-model="config.min_weight" type="number" size="small"></el-input>
			</el-form-item>
			<el-form-item label="订单发货时长:">
				<div class="flex">
					<el-input 
						style="width: 130px;"
						v-model="config.send_order_time" type="number" size="small"></el-input>
						<span style="margin:0 5px;">分</span>
					<span v-if="config.send_order_time">
						({{computedSendTime}})
					</span>
				</div>
			</el-form-item>
			<el-form-item label="订单交付时长:">
				<div class="flex">
					<el-input 
						style="width: 130px;"
						v-model="config.get_order_time" type="number" size="small"></el-input>
						<span style="margin:0 5px;">分</span>
					<span v-if="config.get_order_time">
						({{computedOrderTime}})
					</span>
				</div>
			</el-form-item>
			<el-form-item label="">
				<el-button type="primary" size="mini" @click="save">保存</el-button>
			</el-form-item>
		</el-form>
		
	</div>
</template>

<script>
	export default {
		data(){
			return {
				config:{
					status:'',
					fixNum:'',
					max_weight:'',
					min_weight:'',
					colse_time:null,
					open_time:null,
					is_auto_open:'0',
					get_order_time:'',
					send_order_time:''
				}
			}
		},
		mounted() {
			this.lodeStatus()
		},
		computed:{
			computedOrderTime:function(){
				var minutes = this.config.get_order_time
				
				// 计算天数
				const days = Math.floor(minutes / (24 * 60));
				// 计算小时数
				const hours = Math.floor((minutes % (24 * 60)) / 60);
				// 计算分钟数
				const remainingMinutes = minutes % 60;
				
				function Time(time) {
					return time
				  // return time > 9 ? time : '0' + time
				}
				return ` ${Time(days)}天 ${Time(hours)}小时 ${Time(remainingMinutes)} 分钟`
				
			},
			computedSendTime:function(){
				var minutes = this.config.send_order_time
				
				// 计算天数
				const days = Math.floor(minutes / (24 * 60));
				// 计算小时数
				const hours = Math.floor((minutes % (24 * 60)) / 60);
				// 计算分钟数
				const remainingMinutes = minutes % 60;
				
				function Time(time) {
					return time
				  // return time > 9 ? time : '0' + time
				}
				return ` ${Time(days)}天 ${Time(hours)}小时 ${Time(remainingMinutes)} 分钟`
				
			},
		},
		methods:{
			save(){
				if(this.config.is_auto_open==1){
					if(!this.config.open_time) return this.$message.error('请选择开始时间')
					if(!this.config.colse_time) return this.$message.error('请选择关闭时间')
				}
				this.$post('/homeSet/setGoldOpen',this.config,res=>{
					this.$message.success('操作成功')
				})
			},
			lodeStatus(){
				this.$post('/homeSet/getGoldOpen',{},res=>{
					let result = res.data.data
					for(let i in this.config){
						this.config[i] = result[i]
					}
				})
			},
		}
	}
</script>

<style>
</style>